﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using LongNet.Util;

namespace LongNet.Config
{
    internal class ConfigFileSerializer<T>
         where T : FileConfigEntity, new()
    {
        #region Properties

        public ConfigFileType FileType { get; set; }

        #endregion

        #region Constructor

        public ConfigFileSerializer(ConfigFileType fileType)
        {
            FileType = fileType;
        }

        #endregion

        #region Methods

        public T Load(string configPath)
        {
            if (FileType == ConfigFileType.Xml)
                return Serializer.ConvertFromXmlFile<T>(configPath);
            else
                return Serializer.ConvertFromBinaryFile<T>(configPath);
        }

        public void Save(T configEntity, string configPath)
        {
            if (FileType == ConfigFileType.Xml)
                Serializer.ConvertToXmlFile(configEntity, configPath);
            else
                Serializer.ConvertToBinaryFile(configEntity, configPath);
        }

        #endregion
    }
}
